import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '工作台', icon: '工作台' }
    }]
  },
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/manage-base-info',
    component: Layout,
    redirect: '/manage-base-info/warehouse',
    name: 'manage-base-info',
    meta: { title: '基础信息管理', icon: '基础信息管理' },
    children: [
      {
        path: 'warehouse',
        name: 'warehouse',
        component: () => import('@/views/manage-base-info/warehouse'),
        meta: {
          title: '仓库管理', icon: '点',
          BtnText: {
            number: '仓库编号',
            name: '仓库名称',
            state: '仓库状态'
          },
          Btn: {
            BtnOne: '编辑',
            BtnTwo: '停用',
            BtnThree: '删除'
          },
          TableText: {
            onePo: '仓库编码',
            twoPo: '仓库名称',
            threePo: '仓库类型',
            fourPo: '省/市/区',
            fixPo: '详细地址',
            sixPo: '仓库状态',
            sevenPo: '仓库面积',
            eightPo: '库区数量',
            ninePo: '负责人',
            tenPo: '联系电话',
            tenOnPo: '更新时间'
          }
        }
      },
      {
        path: 'warehouse/details',
        name: 'details',
        component: () => import('@/views/manage-base-info/warehouse/details'),
        meta: { title: '新增仓库' },
        hidden: true
      },
      {
        path: 'area',
        name: 'area',
        component: () => import('@/views/manage-base-info/area'),
        meta: {
          title: '库区管理', icon: '点',
          SpecialA: true,
          BtnText: {
            number: '仓库名称',
            name: '库区名称',
            state: '仓库状态'
          },
          Btn: {
            BtnOne: '编辑',
            BtnTwo: '停用',
            BtnThree: '删除'
          },
          TableText: {
            onePo: '所属仓库',
            twoPo: '库区编号',
            threePo: '库区名称',
            fourPo: '温度类型',
            fixPo: '承重类型',
            sixPo: '用途属性',
            sevenPo: '库区状态',
            eightPo: '负责人',
            ninePo: '联系电话',
            tenPo: '库位数量',
            tenOnPo: '更新时间'
          }
        }
      },
      {
        path: 'area/details',
        name: 'details',
        component: () => import('@/views/manage-base-info/area/details'),
        meta: { title: '新增库区' },
        hidden: true
      },
      {
        path: 'location',
        name: 'location',
        component: () => import('@/views/manage-base-info/location'),
        meta: {
          title: '库位管理', icon: '点',
          BtnText: {
            number: '库区名称',
            name: '库位名称',
            state: '库位状态'
          },
          Btn: {
            BtnOne: '编辑',
            BtnTwo: '停用',
            BtnThree: '删除'
          },
          TableText: {
            onePo: '所属仓库',
            twoPo: '库区编号',
            threePo: '库区名称',
            fourPo: '库位编号',
            fixPo: '库位名称',
            sixPo: '温度类型',
            sevenPo: '承重类型',
            eightPo: '用途属性',
            ninePo: '停用状态',
            tenPo: '承载上限',
            tenOnPo: '更新时间'
          }
        }
      },
      {
        path: 'location/details',
        name: 'details',
        component: () => import('@/views/manage-base-info/location/details'),
        meta: { title: '新增库位' },
        hidden: true
      },
      {
        path: 'location-view',
        name: 'location-view',
        component: () => import('@/views/manage-base-info/location-view'),
        meta: { title: '库位视图', icon: '点' }
      },
      {
        path: 'goods',
        name: 'goods',
        component: () => import('@/views/manage-base-info/goods'),
        meta: {
          title: '货品管理', icon: '点',
          BtnText: {
            number: '货品编号',
            name: '货品名称',
            state: '货主名称'
          },
          Btn: {
            BtnOne: '编辑',
            BtnThree: '删除'
          },
          TableText: {
            onePo: '货品类型名称',
            twoPo: '货品编号',
            threePo: '货品条码',
            fourPo: '货品名称',
            fixPo: '货主名称',
            sixPo: '质检方式',
            sevenPo: '温度要求',
            eightPo: '承重要求',
            ninePo: '指定库区',
            tenPo: '体积m3',
            tenOnPo: '单价（元）',
            tenTwoPo: '单位',
            tenThreePo: '质保天数（天）',
            tenFourPo: '更新时间'
          }}
      },
      {
        path: 'goods/details',
        name: 'details',
        component: () => import('@/views/manage-base-info/goods/details'),
        meta: { title: '新增货品' },
        hidden: true
      },
      {
        path: 'goods-type',
        name: 'goods-type',
        component: () => import('@/views/manage-base-info/goods-type'),
        meta: {
          title: '货品类型管理', icon: '点',
          BtnText: {
            number: '类型编号',
            name: '类型名称',
            state: ''
          },
          Btn: {
            BtnOne: '编辑',
            BtnThree: '删除'
          },
          TableText: {
            onePo: '货品类型编号',
            twoPo: '货品类型名称',
            threePo: '更新时间'
          }}
      }
    ]
  },

  {
    path: '/manage-business',
    component: Layout,
    redirect: '/manage-business/goods-owner',
    name: 'manage-business',
    meta: { title: '商务管理', icon: '商务管理' },
    children: [
      {
        path: 'goods-owner',
        name: 'goods-owner',
        component: () => import('@/views/manage-business/goods-owner'),
        meta: {
          title: '货主管理', icon: '点',
          BtnText: {
            number: '货主编号',
            name: '货主名称',
            state: '联系人'
          },
          Btn: {
            BtnOne: '查看详情',
            BtnTwo: '编辑',
            BtnThree: '删除'
          },
          TableText: {
            onePo: '货主编号',
            twoPo: '货主名称',
            threePo: '联系人',
            fourPo: '联系人电话',
            fixPo: '联系邮箱',
            sixPo: '省/市/区',
            sevenPo: '详细地址',
            eightPo: '更新时间'
          }}
      },
      {
        path: 'goods-owner/details',
        name: 'details',
        component: () => import('@/views/manage-business/goods-owner/details'),
        meta: { title: '新增货主' },
        hidden: true
      },
      {
        path: 'task-picking',
        name: 'task-picking',
        component: () => import('@/views/manage-business/task-picking'),
        meta: {
          title: '承运商管理', icon: '点',
          BtnText: {
            number: '承运商编号',
            name: '承运商名称',
            state: '联系人'
          },
          TableText: {
            onePo: '承运商编号',
            twoPo: '承运商名称',
            threePo: '联系人',
            fourPo: '联系人电话',
            fixPo: '联系邮箱',
            sixPo: '省/市/区',
            sevenPo: '详细地址',
            eightPo: '更新时间'
          }}
      }
    ]
  },

  {
    path: '/manage-storage',
    component: Layout,
    redirect: '/manage-storage/list',
    name: 'manage-storage',
    meta: {
      title: '库内管理',
      icon: '库内管理'
    },
    children: [
      {
        path: 'list',
        name: 'list',
        component: () => import('@/views/manage-storage/list'),
        meta: { title: '盘点单', icon: '点',
          BtnText: {
            number: '盘点单号',
            name: '盘点状态',
            state: '盘点类型',
            user: '货主',
            total: '盘点货区'
          },
          Btn: {
            BtnOne: '查看详情'
          },
          TableText: {
            onePo: '盘点单号',
            twoPo: '货主',
            threePo: '盘点单状态',
            fourPo: '创建时间',
            fixPo: '计划盘点时间',
            sixPo: '盘点原因',
            sevenPo: '盘点维度',
            eightPo: '盘点类型',
            ninePo: '盘点仓库',
            tenPo: '盘点库区',
            tenOnPo: '创建人'
          }}
      },
      {
        path: 'list-task',
        name: 'list-task',
        component: () => import('@/views/manage-storage/list-task'),
        meta: { title: '盘点任务', icon: '点' }
      },
      {
        path: 'storage-lose-profit',
        name: 'storage-lose-profit',
        component: () => import('@/views/manage-storage/storage-lose-profit'),
        meta: { title: '库存损益', icon: '点' }
      },
      {
        path: 'latest-storage',
        name: 'latest-storage',
        component: () => import('@/views/manage-storage/latest-storage'),
        meta: { title: '实时库存', icon: '点' }
      }
    ]
  },
  {
    path: '/manage-storage-in',
    component: Layout,
    redirect: '/manage-storage-in/list-in',
    name: 'manage-storage-in',
    meta: { title: '入库管理', icon: '入库管理' },
    children: [
      {
        path: 'list-in',
        name: 'list-in',
        component: () => import('@/views/manage-storage-in/list-in'),
        meta: { title: '入库单', icon: '点' }
      },
      {
        path: 'task-receive',
        name: 'task-receive',
        component: () => import('@/views/manage-storage-in/task-receive'),
        meta: { title: '收货任务', icon: '点' }
      },
      {
        path: 'task-add',
        name: 'task-add',
        component: () => import('@/views/manage-storage-in/task-add'),
        meta: { title: '上架任务', icon: '点' }
      }
    ]
  },
  {
    path: '/manage-storage-out',
    component: Layout,
    redirect: '/manage-storage-out/list-out',
    name: 'manage-storage-out',
    meta: { title: '出库管理', icon: '出库' },
    children: [
      {
        path: 'list-out',
        name: 'list-out',
        component: () => import('@/views/manage-storage-out/list-out'),
        meta: { title: '出库单', icon: '点' }
      },
      {
        path: 'task-picking',
        name: 'task-picking',
        component: () => import('@/views/manage-storage-out/task-picking'),
        meta: { title: '拣货任务', icon: '点' }
      },
      {
        path: 'manage-task-transfer',
        name: 'manage-task-transfer',
        component: () => import('@/views/manage-storage-out/manage-task-transfer'),
        meta: { title: '交接任务', icon: '点' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
